{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 1.9 \u67e5\u627e\u4e24\u5b57\u5178\u7684\u76f8\u540c\u70b9\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u600e\u6837\u5728\u4e24\u4e2a\u5b57\u5178\u4e2d\u5bfb\u5bfb\u627e\u76f8\u540c\u70b9\uff08\u6bd4\u5982\u76f8\u540c\u7684\u952e\u3001\u76f8\u540c\u7684\u503c\u7b49\u7b49\uff09\uff1f"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8003\u8651\u4e0b\u9762\u4e24\u4e2a\u5b57\u5178\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "a = {\n    'x' : 1,\n    'y' : 2,\n    'z' : 3\n}\n\nb = {\n    'w' : 10,\n    'x' : 11,\n    'y' : 2\n}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4e3a\u4e86\u5bfb\u627e\u4e24\u4e2a\u5b57\u5178\u7684\u76f8\u540c\u70b9\uff0c\u53ef\u4ee5\u7b80\u5355\u7684\u5728\u4e24\u5b57\u5178\u7684 keys() \u6216\u8005 items() \u65b9\u6cd5\u8fd4\u56de\u7ed3\u679c\u4e0a\u6267\u884c\u96c6\u5408\u64cd\u4f5c\u3002\u6bd4\u5982\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Find keys in common\na.keys() & b.keys() # { 'x', 'y' }\n# Find keys in a that are not in b\na.keys() - b.keys() # { 'z' }\n# Find (key,value) pairs in common\na.items() & b.items() # { ('y', 2) }"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8fd9\u4e9b\u64cd\u4f5c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u4fee\u6539\u6216\u8005\u8fc7\u6ee4\u5b57\u5178\u5143\u7d20\u3002\n\u6bd4\u5982\uff0c\u5047\u5982\u4f60\u60f3\u4ee5\u73b0\u6709\u5b57\u5178\u6784\u9020\u4e00\u4e2a\u6392\u9664\u51e0\u4e2a\u6307\u5b9a\u952e\u7684\u65b0\u5b57\u5178\u3002\n\u4e0b\u9762\u5229\u7528\u5b57\u5178\u63a8\u5bfc\u6765\u5b9e\u73b0\u8fd9\u6837\u7684\u9700\u6c42\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Make a new dictionary with certain keys removed\nc = {key:a[key] for key in a.keys() - {'z', 'w'}}\n# c is {'x': 1, 'y': 2}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4e00\u4e2a\u5b57\u5178\u5c31\u662f\u4e00\u4e2a\u952e\u96c6\u5408\u4e0e\u503c\u96c6\u5408\u7684\u6620\u5c04\u5173\u7cfb\u3002\n\u5b57\u5178\u7684 keys() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5c55\u73b0\u952e\u96c6\u5408\u7684\u952e\u89c6\u56fe\u5bf9\u8c61\u3002\n\u952e\u89c6\u56fe\u7684\u4e00\u4e2a\u5f88\u5c11\u88ab\u4e86\u89e3\u7684\u7279\u6027\u5c31\u662f\u5b83\u4eec\u4e5f\u652f\u6301\u96c6\u5408\u64cd\u4f5c\uff0c\u6bd4\u5982\u96c6\u5408\u5e76\u3001\u4ea4\u3001\u5dee\u8fd0\u7b97\u3002\n\u6240\u4ee5\uff0c\u5982\u679c\u4f60\u60f3\u5bf9\u96c6\u5408\u7684\u952e\u6267\u884c\u4e00\u4e9b\u666e\u901a\u7684\u96c6\u5408\u64cd\u4f5c\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u952e\u89c6\u56fe\u5bf9\u8c61\u800c\u4e0d\u7528\u5148\u5c06\u5b83\u4eec\u8f6c\u6362\u6210\u4e00\u4e2a set\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5b57\u5178\u7684 items() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5305\u542b (\u952e\uff0c\u503c) \u5bf9\u7684\u5143\u7d20\u89c6\u56fe\u5bf9\u8c61\u3002\n\u8fd9\u4e2a\u5bf9\u8c61\u540c\u6837\u4e5f\u652f\u6301\u96c6\u5408\u64cd\u4f5c\uff0c\u5e76\u4e14\u53ef\u4ee5\u88ab\u7528\u6765\u67e5\u627e\u4e24\u4e2a\u5b57\u5178\u6709\u54ea\u4e9b\u76f8\u540c\u7684\u952e\u503c\u5bf9\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5c3d\u7ba1\u5b57\u5178\u7684 values() \u65b9\u6cd5\u4e5f\u662f\u7c7b\u4f3c\uff0c\u4f46\u662f\u5b83\u5e76\u4e0d\u652f\u6301\u8fd9\u91cc\u4ecb\u7ecd\u7684\u96c6\u5408\u64cd\u4f5c\u3002\n\u67d0\u79cd\u7a0b\u5ea6\u4e0a\u662f\u56e0\u4e3a\u503c\u89c6\u56fe\u4e0d\u80fd\u4fdd\u8bc1\u6240\u6709\u7684\u503c\u4e92\u4e0d\u76f8\u540c\uff0c\u8fd9\u6837\u4f1a\u5bfc\u81f4\u67d0\u4e9b\u96c6\u5408\u64cd\u4f5c\u4f1a\u51fa\u73b0\u95ee\u9898\u3002\n\u4e0d\u8fc7\uff0c\u5982\u679c\u4f60\u786c\u8981\u5728\u503c\u4e0a\u9762\u6267\u884c\u8fd9\u4e9b\u96c6\u5408\u64cd\u4f5c\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u5148\u5c06\u503c\u96c6\u5408\u8f6c\u6362\u6210 set\uff0c\u7136\u540e\u518d\u6267\u884c\u96c6\u5408\u8fd0\u7b97\u5c31\u884c\u4e86\u3002"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}